home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 15 / BBS in a box XV-2.iso / Files II / Prog / B-C / C++ FAQ Reference 1.0.sit / C++ FAQ Reference 1.0.rsrc / TEXT_1629.txt < prev    next >
Encoding:
Text File  |  1993-06-30  |  563 b   |  15 lines

  1. Make constructors protected and define 'friend' or 'static' fns that return a ptr to objects created via 'new' (the ctors must be protected rather than private, otherwise you couldn't derive from the class).  Ex:
  2.  
  3.     class X {    //only want to allow dynamicly allocated X's
  4.     protected:
  5.                X();
  6.                X(int i);
  7.                X(const X& x);
  8.       virtual ~X();
  9.     public:
  10.       static X* create()           { return new X();  }
  11.       static X* create(int i)      { return new X(i); }
  12.       static X* create(const X& x) { return new X(x); }
  13.     };
  14.  
  15.     X* Xptr = X::create(5);